
#ifndef __RESOLVER_H
#define __RESOLVER_H

#include <map>
#include <string>

struct resolve_metadata_metadata; 

/** This resolves human-readable names into UIDs, human-readable properties
 * into the correct data, and tree traversal queries. All are specified as
 * a hierarchy of spaces, where the parent actor contains a tree including
 * all of its children. */
class Resolver
{
   public:
      /** An enumerant that denotes the cacheability of the item of metadata
       * requested, which influences how the system relays this to the user. */
      enum cacheabletype {   ITEM_NOT_CACHEABLE         = 0,
                             ITEM_CACHEABLE_IF_NONEMPTY = 1,
                             ITEM_CACHEABLE_ALWAYS      = 2 };
      static const char *reserved_names[];
      static const struct resolve_metadata_metadata metadata_names[];
      Resolver(apr_pool_t *imp);
      virtual ~Resolver();
      void reset();
      void clearCache();
      const char *getCached(const char *hierarchy);
      const char *getTempCached(const char *hierarchy);
      int validateNewNameNotIllegal(const char *newname);
      const char *get(const char *hierarchy);
      const char *refresh(const char *hierarchy);
      virtual void renameActorID(const char *actorid, const char *actoralias) = 0;
      virtual const char *resolveName(const char *hierarchy) = 0;
      virtual const char *resolveType(const char *hierarchy) = 0;
      virtual const char *resolveProgress(const char *hierarchy) = 0;
      virtual const char *resolveMetadata(const char *parent, const char *suffix) = 0;
      virtual const char *resolveParent(const char *parent, const char *suffix) = 0;
      virtual const char *resolveChildren(const char *parent, const char *suffix) = 0;
      const std::map<std::string, std::string> &getCachedMap() { return caching_map; }
   protected:
      void initPool(apr_pool_t *iparent);
      const char *cacheAndReturn(const char *hierarchy, const char *resolution);
      const char *cacheTempAndReturn(const char *hierarchy, const char *resolution);
      /** The parent memory pool for the class. */
      apr_pool_t *parent_pool;
      /** The memory pool for the class. */
      apr_pool_t *mp;
      /** The permanent memory pool for the class. */
      apr_pool_t *pmp;
      /** Is the resolver valid? */
      int valid;
      /** The map containing the cached items. */
      std::map<std::string, std::string> caching_map;
};

/** A struct defining one the possible metadata fields. */
typedef struct resolve_metadata_metadata
{
   const char *simple_key;
   const char *broker_message_key;
   Resolver::cacheabletype cacheable;
} ResolveMetadataMetadata;

#endif
